<?php

/*
 * Show form for reporting abuse
 */

class ReportAbuse extends CWidget {

    public $model;

    public function run() {
	$aStatementAbuse = StatementAbuse::getStatement();
	$check = array();
	//check wheather user send abuse?
	if (user()->id) {
	    if ($this->model instanceof Posts) {
		$check = Yii::app()->db->createCommand('SELECT user_id FROM {{abuses}} WHERE user_id=' . user()->id . '
						    AND item_id=' . $this->model->post_id . ' 
						    AND type=' . Abuse::POST_TYPE)->queryRow();
	    } elseif ($this->model instanceof Comment) {
		$check = Yii::app()->db->createCommand('SELECT user_id FROM {{abuses}} WHERE user_id=' . user()->id . '
						    AND item_id=' . $this->model->comment_id . ' 
						    AND type=' . Abuse::COMMENT_TYPE)->queryRow();
	    }
	}

	$this->render('report_abuse', array('model' => $this->model, 'aStatementAbuse' => $aStatementAbuse, 'check' => $check));
    }

}

